import { getSetting, chooseAddress, openSetting, showModal,showToast } from "../../utils/asyncWx.js";
import regeneratorRuntime from '../../lib/runtime/runtime';


Page({
  data: {
    address: {},
    cart: [],
    totalPrice: 0,
    totalNum: 0
  },

  onShow() {
    // 获取缓存中的收货地址
    const address = wx.getStorageSync('address');
    // 获取缓存中的购物车信息
    let cart = wx.getStorageSync("cart") || [];
    // 过滤后的购物车数组
    cart=cart.filter(v=>v.checked);
    
    // 总价格 总数量
    let totalPrice = 0;
    let totalNum = 0;
    cart.forEach(v => {
        totalPrice += v.num * v.goods_price;
        totalNum += v.num;
    })


    this.setData({
      cart,
      totalPrice,
      totalNum,
      address
    });

  },

  // 点击支付

  handleOrderPay(){
    // 1 判断缓存中有无token
    const token=wx.getStorageSync("token");
    // 2 判断
    if (!token) {
      wx.navigateTo({
        url: '/pages/auth/index'
      });
      return;
    }

    console.log("已经存在token");
      
  }
})